//
// Created by Administrator on 2024/7/15.
// 二分法查找
//

#include <iostream>
#include <vector>
using namespace std;


int count_times(vector<int> v, int x, int count, int n)
{
    if (count > n)
        return -1;
    int m = (count + n) / 2;
    if (x<v[m])
        return count_times(v, x, count, m - 1);
    else if (x>v[m])
        return count_times(v, x, m + 1, n);
    else
        return m;
}
int main()
{
    vector<int> l{1,2,3,5,6,7,9};
    int n = 4;
    cout << count_times(l, n, 0, l.size() - 1);
    return 0;
}